package org.iipg.data.sync.crawler;

import java.util.List;
import java.util.concurrent.CyclicBarrier;

import org.iipg.data.sync.common.SyncConfiguration;
import org.iipg.data.sync.common.WorkerProp;

public class DefaultCrawler implements WorkerConstants {

	public static void main(String[] args) {

		SyncConfiguration conf = new SyncConfiguration("sync-news.xml");

		List<WorkerProp> props = conf.getWorkerProps();

		final long start = System.currentTimeMillis();  
		CyclicBarrier barrier = new CyclicBarrier(props.size(), new Runnable(){  
			@Override  
			public void run() {  
				long end = System.currentTimeMillis();  
				System.out.println("total time : "+(end-start)+"ms");  
			}  
		});  

		for (int i=0; i<props.size(); i++) {
			WorkerProp prop = props.get(i);
			Worker worker = WorkerFactory.newInstance(prop);
			worker.setBarrier(barrier, i);
			
			if (worker != null)
				worker.start();
		}
	}

}
